<?php


namespace app\models;

use Yii;

/**
 * This is the model class for table "users".
 *
 * @property int $id
 * @property string $username
 * @property string $userpwd
 * @property string $tel
 * @property string $email
 */
class Users extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'users';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['username', 'email'], 'string', 'max' => 30],
            [['userpwd'], 'string', 'max' => 32],
            [['tel'], 'string', 'max' => 11],
            [['tel'], 'unique'],
            [['email'], 'unique'],
            [['username'],'required'],
            [['userpwd'],'required'],
            [['tel'],'required'],
            [['email'],'required']
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'username' => 'Username',
            'userpwd' => 'Userpwd',
            'tel' => 'Tel',
            'email' => 'Email',
        ];
    }
    //添加数据
    public function addData($data){
        $this->username=$data['username'];
        $this->userpwd=$data['userpwd'];
        $this->tel=$data['tel'];
        $this->email=$data['email'];
        return $this->save();
    }
}
